package com.syuchen.common;

import java.io.Serializable;
import java.util.Objects;

public class URL implements Serializable {

    public static final String UDP_PROTO = "UDP";
    public static final String TCP_PROTO = "TCP";

    private String hostname;
    private Integer port;
    private String transProtocol = TCP_PROTO;//服务支持的传输层协议

    public URL(String hostname, Integer port) {
        this.hostname = hostname;
        this.port = port;
    }

    public URL(String hostname, Integer port, String transProtocol) {
        this.hostname = hostname;
        this.port = port;
        this.transProtocol = transProtocol;
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getTransProtocol() {
        return transProtocol;
    }

    public void setTransProtocol(String transProtocol) {
        this.transProtocol = transProtocol;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        URL url = (URL) o;
        return Objects.equals(hostname, url.hostname) && Objects.equals(port, url.port) && ((URL) o).transProtocol.equals(transProtocol);
    }

    @Override
    public int hashCode() {
        return Objects.hash(hostname, port, transProtocol);
    }
}
